<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">用户ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="user_id" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">时间</label>
                    <div class="layui-input-block" style="width: 350px;">
                        <input type="text" name="start_time" placeholder="搜索开始时间" autocomplete="off" class="layui-input" style="width: 167px;display: inline" id="start_time_input">
                        -
                        <input type="text" name="end_time" placeholder="搜索截止日期" autocomplete="off" class="layui-input" style="width: 167px;display: inline" id="end_time_input">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <button class="layui-btn layuiadmin-btn-userlist" lay-submit lay-filter="LAY-user-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card-body">

            <table id="LAY-user-feedback" lay-filter="LAY-user-feedback"></table>

            <script type="text/html" id="table-feedback-operation">
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>

        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'laydate', 'admin'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , admin = layui.admin
            , laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start_time_input',
            type: 'datetime'
        });
        laydate.render({
            elem: '#end_time_input',
            type: 'datetime'
        });
        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-user-feedback', {
                page: {
                    curr: 1   //默认从第一页开始搜索
                },
                where: field
            });
        });

        table.on("sort(LAY-user-feedback)", function (obj) {
            table.reload("LAY-user-feedback", {
                initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                where: {
                    //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    field: obj.field, //排序字段   在接口作为参数字段  field order
                    order: obj.type, //排序方式   在接口作为参数字段  field order
                },
            });
        });


        // 加载数据
        table.render({
            elem: '#LAY-user-feedback'
            , url: '/admin/feedback/getList'
            , cols: [[
                {field: 'id', width: 80, title: 'ID',  sort: true},
                {field: 'uid', width: 100, title: '用户ID'},
                {
                    field: '', width: 150, title: '用户名'
                    , templet: function (d) {
                        if (d.user) {
                            return d.user.account;
                        }
                        return '';
                    }
                },

                {field: 'title', width: 250, title: '标题',},
                {field: 'content', minWidth: 200, maxWidth: 400, title: '内容',},
                {field: 'created_at', width: 200, title: '时间',},
                {title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#table-feedback-operation'}
            ]]
            , page: true
            , limit: 20
            , height: 'full-180'
            , text: '对不起，加载出现异常！'
            , even: true
        });

        //监听工具条
        table.on('tool(LAY-user-feedback)', function (obj) {
            if (obj.event == "del") {
                layer.confirm('确认删除？', function (index) {
                    admin.req({
                        url: '/admin/feedback/delInfo'
                        , data: {"id": obj.data.id}
                        , success(res) {
                            if (res.code == 0) {
                                table.reload("LAY-user-feedback");
                                layer.msg(res.msg, {icon: 1});
                            } else {
                                layer.msg(res.msg, {icon: 5});
                            }
                        }
                    });
                });
            }
        });


    });
</script>
</body>
</html>
